/*
 * Copyright 2011 Niklas Kyster Rasmussen
 * 
 * This file is part of WotXP.
 *
 * WotXP is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * WotXP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WotXP; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

package net.nikr.wot.cmd.data;

import net.nikr.wot.calc.Calc;
import net.nikr.wot.calc.Traning;


public class Data {
	
	private Traning traning;
	private int traningLvl;
	
	private int avg = 0;
	private int crew = 0;	
	private int primary = 0;
	private int secondary1 = 0;
	private int secondary2 = 0;
	private int secondary3 = 0;

	public Data() {}	
	
	private void update(){
		traning = Traning.PRIMARY;
		traningLvl = primary;
		if (primary == 100){
			traning = Traning.SECONDARY1;
			traningLvl = secondary1;
			if (secondary1 == 100){
				traning = Traning.SECONDARY2;
				traningLvl = secondary2;
				if (secondary2 == 100){
					traning = Traning.SECONDARY3;
					traningLvl = secondary3;
				}
			}
			
		}
	}

	public void setPrimary(int primary) {
		if (primary > 100) primary = 100;
		this.primary = primary;
		update();
	}

	public void setSecondary1(int secondary1) {
		if (secondary1 > 100) secondary1 = 100;
		this.secondary1 = secondary1;
		update();
	}

	public void setSecondary2(int secondary2) {
		if (secondary2 > 100) secondary2 = 100;
		this.secondary2 = secondary2;
		update();
	}

	public void setSecondary3(int secondary3) {
		if (secondary3 > 100) secondary3 = 100;
		this.secondary3 = secondary3;
		update();
	}

	public void setAvg(int avg) {
		this.avg = avg;
	}

	public void setCrew(int crew) {
		this.crew = crew;
	}

	public int getPrimary() {
		return primary;
	}

	public int getSecondary1() {
		return secondary1;
	}

	public int getSecondary2() {
		return secondary2;
	}

	public int getSecondary3() {
		return secondary3;
	}
	
	
	public int getPrimaryXpLeft() {
		return Calc.xpLeft(primary, Traning.PRIMARY);
	}

	public int getSecondary1XpLeft() {
		return getPrimaryXpLeft()+Calc.xpLeft(secondary1, Traning.SECONDARY1);
	}

	public int getSecondary2XpLeft() {
		return getSecondary1XpLeft()+Calc.xpLeft(secondary2, Traning.SECONDARY2);
	}

	public int getSecondary3XpLeft() {
		return getSecondary2XpLeft()+Calc.xpLeft(secondary3, Traning.SECONDARY3);
	}
	
	public int getPrimaryBattlesLeft() {
		return Calc.battlesLeft(getPrimaryXpLeft(), avg);
	}
	public int getSecondary1BattlesLeft() {
		return Calc.battlesLeft(getSecondary1XpLeft(), avg);
	}
	public int getSecondary2BattlesLeft() {
		return Calc.battlesLeft(getSecondary2XpLeft(), avg);
	}
	public int getSecondary3BattlesLeft() {
		return Calc.battlesLeft(getSecondary3XpLeft(), avg);
	}
	
	public int getPrimaryBattlesLeftRapid() {
		return Calc.battlesLeftRapid(getPrimaryXpLeft(), avg, crew);
	}
	public int getSecondary1BattlesLeftRapid() {
		return Calc.battlesLeftRapid(getSecondary1XpLeft(), avg, crew);
	}
	public int getSecondary2BattlesLeftRapid() {
		return Calc.battlesLeftRapid(getSecondary2XpLeft(), avg, crew);
	}
	public int getSecondary3BattlesLeftRapid() {
		return Calc.battlesLeftRapid(getSecondary3XpLeft(), avg, crew);
	}
	
	public boolean isBattles(){
		return (avg != 0 && crew != 0);
	}

	public Traning getTraning() {
		return traning;
	}

	public int getTraningLvl() {
		return traningLvl;
	}
}
